package com.qianxunclub.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStreamWriter;

public class FileUtil {

	public static boolean export(String filePath, String fileName,
			String context) {
		OutputStreamWriter out = null;
		try {

			File dir = new File(filePath);

			if (!dir.exists()) {
				dir.mkdirs();
			}

			File file = new File(filePath + fileName);

			out = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");

			out.write(context);

			return true;

		} catch (Exception e) {

			e.printStackTrace();

			return false;
		} finally {
			try {
				if (null != out) {
					out.flush();
					out.close();
				}
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		}

	}
	
	 public static String ReadFile(String path) {  
	        File file = new File(path);  
	        BufferedReader reader = null;  
	        String laststr = "";  
	        try {  
	            reader = new BufferedReader(new FileReader(file));  
	            String tempString = null;  
	            while ((tempString = reader.readLine()) != null) {  
	                laststr = laststr + tempString;  
	            }  
	            reader.close();  
	        } catch (IOException e) {  
	            e.printStackTrace();  
	        } finally {  
	            if (reader != null) {  
	                try {  
	                    reader.close();  
	                } catch (IOException e1) {  
	                }  
	            }  
	        }  
	        return laststr;  
	    }  
}
